<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
 * product and info search page
 * @author		Jade Xia
 * @copyright	Copyright (c) 2010 - 2011 天夏网络.
 * @link		http://www.tianxianet.com
 *
 */
class Search extends Controller
{
	var $site_title;
	var $floatim = '';
	
	function Search()
	{
		parent::Controller();
		$this->load->database();
		$this->load->model('com_model');
		$this->load->helper('string');
		$this->site_title=$this->config->item('sys_site_title');
		if($this->config->item('sys_is_open_im') == '1')
		{
			$this->floatim = $this->com_model->floatim();
		}
	}
	
	function product()
	{
		parse_str($_SERVER['QUERY_STRING'],$get);
		$catalog_id = 0;
		$keyword = '';
		if(isset($get['catalog_id']) && !empty($get['catalog_id'])) $catalog_id = strip_quotes($get['catalog_id']);
		if(isset($get['keyword']) && !empty($get['keyword'])) $keyword = strip_quotes($get['keyword']);
		$sql = 'SELECT id,title,title_color,summary,market_price,small_pic_path,pNum,big_pic_path FROM '.$this->db->dbprefix."product WHERE is_trash = 0";
		if($keyword) $sql .= " AND title like '%{$keyword}%'";
		if($catalog_id > 0) $sql .= " AND catalog_id like '%,{$catalog_id},%'";
		$sql .= ' ORDER BY seqorder DESC,id DESC';
		$offset = $this->uri->segment($this->com_model->uri_segnum+1, 0);
		$page = array(
			'page_base' => CTL_FOLDER.'search/product',
			'offset'   => $offset,
			'per_page' => 12,
			'sql' => $sql
		);
		$query = $this->common_model->get_page_records($page);
		$nav = '产品搜索结果';
		$data = array(
			'site_title'		=> $nav.'--'.$this->site_title,
			'product'		=> $query['query'],
			'paginate'		=> $query['paginate'],
			'nav'		=> ' &gt; '.$nav,
			'nav_title'		=> $nav,
			'product_catalog'		=> $this->com_model->parse_pcatalog(0)
		);
		$this->load->view(TPL_FOLDER.'product_search',$data);
	}
	
	function news()
	{
		parse_str($_SERVER['QUERY_STRING'],$get);
		$catalog_id = 0;
		$keyword = '';
		if(isset($get['catalog_id']) && !empty($get['catalog_id'])) $catalog_id = strip_quotes($get['catalog_id']);
		if(isset($get['keyword']) && !empty($get['keyword'])) $keyword = strip_quotes($get['keyword']);
		$sql = 'SELECT id,title,title_color,summary,create_date,pic_path,hits FROM '.$this->db->dbprefix.'news WHERE is_trash = 0';
		if($keyword) $sql .= " AND title like '%{$keyword}%'";
		if($catalog_id > 0) $sql .= " AND catalog_id like '%,{$catalog_id},%'";
		$sql .= ' ORDER BY seqorder DESC,id DESC';
		$offset = $this->uri->segment($this->com_model->uri_segnum+1, 0);
		$page = array(
			'page_base' => CTL_FOLDER.'search/news',
			'offset'   => $offset,
			'per_page' => 15,
			'sql' => $sql
		);
		$query = $this->common_model->get_page_records($page);
		$nav = '新闻搜索结果';
		$data = array(
			'site_title'		=> $nav.'--'.$this->site_title,
			'news'		=> $query['query'],
			'paginate'		=> $query['paginate'],
			'nav'		=> ' &gt; '.$nav,
			'nav_title'		=> $nav,
			'news_catalog'		=> $this->com_model->parse_ncatalog(0),
			'product_catalog'		=> $this->com_model->parse_pcatalog(0)
		);
		$this->load->view(TPL_FOLDER.'news_search',$data);
	}
}
?>